<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>调研试题列表</title>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<script src='<c:url value="/js/boot.js"></c:url>'></script>
<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}

//弹出
		.haha{
		    position: absolute;
		    width: 100%;
		    height: 100%;
		    top: 0px;
		    left: 0px;
		    background: rgba(255, 255, 255, 0.2);
		    z-index:999;
		}
		#dialog{
			position: absolute;
		    top: 60px;
		    width: 65%;
		    left: 17.5%;
		    background: rgb(252, 252, 252);
		    z-index:1000;
			}
			#abc{
			position: absolute;
			top:20%;
			left: 360px;
			z-index: 2;
			} 
					
			.maskLayer{  
			z-index:10;
			opacity:0.3; 
			filter: alpha(opacity=30); 
			background-color:#ccc;
			}
			.questions_stems{
				border: 1px solid #a4a4a4;
				padding: 6px 12px;
				margin:30px 30px 10px 30px;
				font-size: 16px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.options{
				border: 1px solid #a4a4a4;
				padding: 10px 25px;
				margin: 20px 30px;
				font-size: 16px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.options>li{
				padding: 10px 15px;
				font-size: 16px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.answer{
				border: 1px solid #a4a4a4;
				padding: 10px;
				margin: 20px 30px;
				font-size: 16px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.answer_detail{
				border: 1px solid #a4a4a4;
				padding: 10px;
				margin: 20px 30px 40px 30px;
				font-size: 16px;
				font-family: "微软雅黑";
				color: #8B8B8B;
			}
			.answer_detail>p{
				margin-left: 80px;
				max-height: 400px;
				overflow-y: auto;
			}
</style>
<script>
	var testType =[{
		id:"单选题",
		text:"单选题"
	},{
		id:"多选题",
		text:"多选题"
	},{
		id:"判断题",
		text:"判断题"
	},{
		id:"问答题",
		text:"问答题"
	}];
	
</script>


</head>

<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="100px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a><a class="mini-button" id="addBtn" iconCls="icon-add"
					plain="true" onclick="add()">新增</a></td>
				<td width="80px"><a class="mini-button" id="deleteBtn" iconCls="icon-remove"
					plain="true" onclick="_delete()">删除</a></td>
				<td width="100px"><a class="mini-button" id="resetBtn"
					iconCls="icon-reset" plain="true" onclick="reloadList">刷新</a></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;查询日期:&nbsp;&nbsp;<input
						id="starting" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="起始期间..." nullItemText="&lt;无&gt;" />
						<span style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect" tooltip="查询" plain="true">查询</a>	
				</span></td>	
				<td></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px; height: 100%; width: 100%;">
				<div id="datagrid1" class="mini-datagrid gridFull"
					borderStyle="border:1;" showReloadButton="true" pagesize="20"
					sizeList="[20,50,100,200]" allowCellWrap="true"
					allowHeaderWrap="true" idField="No" multiSelect="true"
					showPager="true" allowAlternating="true"
					ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
					style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
					collapseGroupOnLoad="false" showColumnsMenu="true"
					showFilterRow="true" onshowrowdetail="onShowRowDetail">
					<div property="columns">
						<div type="indexcolumn" width="40px"></div>
						<div type="checkcolumn" width="40px"></div>
						<div field="Action" width="70px" headerAlign="center"
							align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
							</a>
						</div>
						<div field="class_id" width="100px" headerAlign="center"
							align="left" allowSort="true">
							题目类型<input id="filter1" property="filter" class="mini-combobox"
								style="width: 100%;" data=testType onValueChanged="onselect"
								emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="question" width="260px" headerAlign="center"
							align="left" allowSort="true">
							题干<input id="filter2" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="label" width="200px" headerAlign="center"
							align="left" allowSort="true">
							题目标签<input id="filter3" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="creater" width="100px" headerAlign="center"
							align="left" allowSort="true">
							制题人<input id="filter4" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="createTime" width="185px"
							dateFormat="yyyy-MM-dd hh:mm:ss" headerAlign="center"
							align="center" allowSort="true">制题时间</div>
						<div field="operation" width="110px" headerAlign="center"
							align="center" allowSort="true">操作</div>
						<!-- <div field="operation" width="100px"
							headerAlign="center" align="center" allowSort="true"></div> -->
						<div name="emptyCol" width='100%' headerAlign="center"
							align="center" cellStyle="padding:0;"></div>
					</div>
				</div>
				<div class="haha" style="display: none;"></div>
				<div id="dialog" style="display: none;">
					<div class="close">
						<img src="<c:url value="/share/img/icon/close_02.png"></c:url>"
							onclick="closeBg()" alt="关闭" style="margin-right: -40px;" />
					</div>
					<div class="questions_stems">
						<font id="question_stem"></font>
					</div>
					<ul class="options" id="select_options">
					</ul>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id="detailPan" class="subPageFrame" frameborder="0"> </iframe>
			</div>
	
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var isKeepStat3 = false;
		var rootPath = '${rootPath}';
		var filterHelper = gridFilter();
		var datagrid1 = mini.get("datagrid1");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var filter4 = mini.get("filter4");
		var splitpan = mini.get("splitterPan");
		var starting = mini.get("starting");
		var ending = mini.get("ending");
		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		//双击
		function gridRowDbClick(e) {
			var id = e.row.id;
			showDetail(id);
		}
		function testShow(data){
			console.log(data);
			$("#dialog").show();
			$(".haha").show();
			$("#question_stem").html(data.question);
			$("#explain_in_detail").html(data.detailed);
			if(data.class_id == "单选题"){
				var selects = data.selects;//题目选项
				var arr = selects.split(",nwebadjj,_");
				var Htmstr="";
				for(var i = 0; i < arr.length;i++){
					var str = String.fromCharCode(i+65);
					Htmstr += "<li>"
						+"<font>"+str+'、'+arr[i]+"</font>"
					+"</li>";
				}
				$("#select_options").html(Htmstr);
				$("#preview_answer").html(data.answer);
			}else if(data.class_id == "多选题"){
				var selects = data.selects;//题目选项
				var arr = selects.split(",nwebadjj,_");
				var Htmstr="";
				for(var i = 0; i < arr.length;i++){
					var str = String.fromCharCode(i+65);
					Htmstr += "<li>"
						+"<font>"+str+'、'+arr[i]+"</font>"
					+"</li>";
				}
				$("#select_options").html(Htmstr);
				$("#preview_answer").html(data.answer);
			}else if(data.class_id == "判断题"){
				$("#select_options").html("<li>&nbsp;"
						+"<font>是</font></li><li>&nbsp;"
						+"<font>否</font></li>");
				if(data.answer =="true"){
					$("#preview_answer").html("是");
				}else if(data.answer =="false"){
					$("#preview_answer").html("否");
				}
			}else if(data.class_id == "解答题"){
				$("#select_options").html("<p style =\"height:40px\"></p>");
				$("#preview_answer").html(data.answer);
			}
			
		}
		function showDetail(id) {
			getMap(id);
			
		}
		function onselect() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			var filterValue4 = filter4.getValue();
			var start = starting.getValue();
			var end = ending.getValue();
			filterHelper.clearFilterData();
			if (start && end && start > end) {
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (start != "") {
				var startTime = new Date(start);
				var tempTime = startTime.valueOf();
				startTime += 24 * 60 * 60 * 1000;
				startTime = new Date(tempTime);
				var year = startTime.getYear() + 1900;
				var month = startTime.getMonth() + 1;
				if (month < 10) {
					month = "0" + month;
				}
				var day = startTime.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				start = year + "-" + month + "-" + day;
				var filterdata = filterHelper.formFilterData("createTime",
						start, '', 'GREATER_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (end != "") {
				var filterdata = filterHelper.formFilterData("createTime",
						end, '', 'LESS_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue1 != ""){
				var filterdata = filterHelper.formFilterData("class_id",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue2 != ""){
				var filterdata = filterHelper.formFilterData("question",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue3 != ""){
				var filterdata = filterHelper.formFilterData("label",
						filterValue3, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue4 != ""){
				var filterdata = filterHelper.formFilterData("creater",
						filterValue4, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/surveyTest/listData' />";
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter3.setText();
			filter4.setValue();
			filter4.setText();
			starting.setValue();
			ending.setText();
			filterHelper.clearFilterData();
			loadGrid1();

		}
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;

			if (field == "Action") {
				var id = row.id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail(\''
						+ id + '\')">[预览]</a>';
			}
			if(field=="operation"){
				var id = row.id;
				var type = row.class_id;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:updateTest(\''
						+ id + '\',\''+type+'\')">[修改]</a>';
			}
			if(field == "label"){
				var label = row.label;
				e.cellHtml = label.replace(/X/g," ");
			}

		}
		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
			$("#dialog").hide();
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#resetBtn').show();
			$('#separatorId').show();
			$('#typeBtn').show();
			$("#toBackBtn").show();
			$("#addBtn").show();
			$("#deleteBtn").show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#resetBtn').hide();
			$('#typeBtn').hide();
			$("#toBackBtn").hide();
			$('#separatorId').hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
		}
		function status3Show() {
			$('#separatorId').show();
			$('#rebackBtn').hide();
			$('#resetBtn').show();
			$('#typeBtn').show();
			$("#toBackBtn").hide();
			$("#addBtn").hide();
			$("#deleteBtn").show();
		}
		function reloadList() {
			datagrid1.reload();
		}
		
		function add(){
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/surveyTest/addMv" />');
		}
		function updateTest(id,type){
			 status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/surveyTest/updateMv/" />' +type+"/"+ id);
		}
		
		function _delete(){
			var ids = datagrid1.getSelecteds();
			var id = "";
			var url = rootPath + "/surveyTest/delete";
			if(ids.length >= 1){
				for(var i = 0; i<ids.length;i++){
					if(id == ""){
						id = ids[i].id;
					}else{
						id += ","+ids[i].id;
					}
					
				}
				mini.confirm("确定删除？", "确定？",
			            function (action) {
			                if (action == "ok") {
			                	$.ajax({
			        				url:url,
			        				method:"post",
			        				dataType:"json",
			        				data:{'data':id},
			        				success:function(data){
			        					if(data.isSuccess){
			        						top.commonTools.showTip("操作成功！", 1);
			        						datagrid1.reload();
			        					}else if(data.errorInfo){
			        						top.commonTools.showTip("没有权限删除！", 2);
			        					}else if(data.isUse){
			        						top.commonTools.showTip("已被引用,无法删除！", 2);
			        					}
			        				},
			        				error:function(){
			        					alert("操作失败！");
			        				}
			        				
			        			});
			                } else {
			                	return;
			                }
			           });
			}else{
				mini.alert("请选择！");
			}
		}
		function getMap(id){
			var url = rootPath + "/surveyTest/testInfo/" + id;
			$.ajax({
				url:url,
				method:"post",
				dataType:"json",
				data:{},
				success:function(data){
					if(data){
						testShow(data);
					}else{
						top.commonTools.showTip("获取信息失败！", 2);
					}
				},
				error:function(){
					alert("失败！");
				}
			});
		}
		function closeBg() {
			$("#dialog").hide();
			$(".haha").hide();
			$("#abc").removeClass("maskLayer");
		}
	</script>
</body>
</html>